/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* modifiedList(vector<int>& nums, ListNode* head) {
        set<int> s(nums.begin(), nums.end());
        auto * ans = head;
        while(s.count(ans->val)){
            ans = ans->next;
        }
        for(auto *p=ans;p->next;){
            if(s.count(p->next->val)){
                p->next = p->next->next;
            }else{
                p = p->next;
            }
        }
        return ans;
    }
};